package com.tbit.main.constant;

import com.tbit.main.exception.BaseException;

import java.util.Map;


/**
 * 响应代码
 *
 * @author Leon
 * 2019年1月23日 下午3:50:32
 */
public class ResponseCode {
    /**
     * 成功
     */
    public final static Integer SUCC = 1;
    /**
     * 失败
     */
    public final static Integer FAIL = 0;
    public final static Integer FAIL_CODE = -101;


    /**
     * 结果布尔值
     */
    public final static String RET = "ret";
    /**
     * 描述
     */
    public final static String MSG = "msg";
    /**
     * 错误代码
     */
    public final static String CODE = "code";
    /**
     * 结果内容
     */
    public final static String DATA = "data";
    /**
     * 分页记录总数
     */
    public final static String RECORDS = "total";


    /**
     * 消息响应
     */
    public static void printException(Map<String, Object> map, BaseException e) {
        map.put(ResponseCode.RET, ResponseCode.FAIL);

        String msg = e.getMessage();
        if (msg != null && msg.contains("%")) {
            String[] array = msg.split("%");
            map.put(ResponseCode.CODE, array[0]);
            map.put(ResponseCode.MSG, array[1]);
        } else {
            map.put(ResponseCode.CODE, "-101");
            map.put(ResponseCode.MSG, e.getMessage());
        }
    }
}
